草庐IT

c++ - QMap 和 std::unique_ptr

全部标签

C++。为什么 std::cout << char + int 打印 int 值?

比方说,我们有:charx='a';inty=1;所以,如果你运行:std::cout它打印98而不是'b'。正如我从here看到的那样只有int参数实现。从现在开始我有两个问题:char+int操作后返回什么类型?为什么没有char参数实现,而是std::cout仍然按预期工作并打印char值? 最佳答案 感谢Fefux,BoPersson和MattiVirkkunen答案是:来自CPPReference:Implicitconversions:arithmeticoperatorsdonotaccepttypessmallert

c++ - 如何使用 OpenSSL API 从其 PEM 格式字符串中读取 RSA 公钥?

我可以使用PEM_read_RSA_PUBKEY函数轻松读取PEM文件。但是,我有一个已内置到可执行文件中的公钥,我不想制作临时文件。阅读此示例/教程:http://hayageek.com/rsa-encryption-decryption-openssl-c/我想出了以下解决方案:#include#include#include#include#include#include#include#includeRSA*createRSA(constchar*key){RSA*rsa=nullptr;BIO*keybio;keybio=BIO_new_mem_buf(key,-1);//

c++ - 在编译时初始化 c++ std::bitset

我正在尝试初始化std::bitset在编译时使用它的一些索引,假设50-75和200-225设置为1。基于http://en.cppreference.com/w/cpp/utility/bitset/bitset看起来我的2个选项是:constexprbitset();constexprbitset(unsignedlonglongval);考虑到第二个构造函数不适用于大索引,有人可以阐明我将如何初始化我的位集吗? 最佳答案 Bitsetconstructorconstexprbitset(unsignedlonglongval

c++ - 性能断言

我知道C支持使用assert()的函数式断言。有没有什么方法/库支持C/C++中的性能断言?有其他语言吗?大致如下:perf_assert_begin(ID1)....../*assertthetimetakenislessthan2000ms*/perf_assert_end(ID1,interval(ID1) 最佳答案 断言可以使用assert来完成来自或static_assert,它内置于语言中。那么,为什么不手动计时然后检查assert中的时差呢?声明?#include#include#ifndefNDEBUGautosta

c++ - 减少 C++ 中的 std::regex 编译时间

我正在使用std::regexr("-?[0-9]*(.[0-9]+)?(e-?[0-9]+)?")来验证数字(整数/定点数/float)。MWE如下:#include#include#include#include#includeusingnamespacestd;boolisNumber(strings){//canignoreallwhitespaces.erase(remove(s.begin(),s.end(),''),s.end());std::regexr("-?[0-9]*(.[0-9]+)?(e-?[0-9]+)?");returnregex_match(s,r);}

C++ 使用 std::get_time 解析 YYMMDD ISO 8601 日期字符串给出意外结果?

我正在尝试解析格式为YYMMDD的日期。作为测试,我尝试了以下代码:#include#include#include#includeintmain(){std::tmt={};std::istringstreamss("191203");ss>>std::get_time(&t,"%y%m%d");if(ss.fail()){std::cout使用Coliru、GCC6.1(C++17)进行测试,输出为:SunMar000:00:001912我期望的是:MonDec300:00:002019格式字符串有问题吗? 最佳答案 你可以使用

c++ - LLVM 在运行时获取声明函数的参数值

我正在编写一个LLVMpass,它需要获取传递给声明函数的值并将其打印出来。请注意声明的函数在LLVMIR中被调用。我已经编写了一个模块传递来迭代程序中的所有指令。获取指令中被调用函数参数的片段如下:for(auto&B:F){for(auto&I:B){if(auto*InvokeI=dyn_cast(&I)){if(InvokeI->getCalledFunction()->getName().str()=="function_name"){errs()getOperand(0))getOperand(1))getOperand(2))但是,如果被调用函数的LLVMIR看起来像这样

c++ - 我什么时候不希望在 Microsoft Visual Studio 中启用 “Control Flow Guard”?

引自MSDN:ControlFlowGuard(CFG)isahighly-optimizedplatformsecurityfeaturethatwascreatedtocombatmemorycorruptionvulnerabilities.Byplacingtightrestrictionsonwhereanapplicationcanexecutecodefrom,itmakesitmuchharderforexploitstoexecutearbitrarycodethroughvulnerabilitiessuchasbufferoverflows.Westronglye

c++ - 构建 C/C++ 代码时的 Gradle 编译器输出

我正在Linux(gcc)和Windows(VS10)下使用gradle构建C/C++代码,就像在Buildingnativesoftwaredocumentation中描述的那样毕业典礼。构建过程很好,我可以启动我的应用程序。如果在构建过程中出现错误,您可以在控制台上看到类似警告和错误的编译器输出。此输出另外写入文件:build/tmp/"TaskName"/output.txt。问题是,如果构建运行没有错误,此输出不会显示在控制台上,但文件已写入。我正在寻找一种方法来在控制台上显示编译器输出,例如警告或错误,即使构建成功也是如此。可以使用更高的日志级别开始gradle构建:grad

c++ - 为什么 std::queue 不实现 insert() 而 std::deque 实现?

我正在阅读std::queue我想知道为什么没有方法可以通过一次操作有效地插入多个元素,而std::deque报价std::deque::insert? 最佳答案 Insert允许插入到结构中的任意位置。std::queue是FIFO结构的抽象接口(interface)。你只能在最后添加东西。底层结构不一定具有插入任意位置的有效方法(例如考虑std::vector)。因此std::queue没有通用的插入成员函数。由于一般的插入函数需要迭代器位置参数,提供多重插入是为了方便,这样您就不必跟踪下一个迭代器位置。推回不需要这个,因为不需